package com.codingman.jpademo2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Demo1 {
	public static void main(String[] args) {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee_unit");
		EntityManager em = emf.createEntityManager();

		em.getTransaction().begin();
		
		Employee d1 = new Employee();
		d1.setId(101);
		d1.setName("Ann");
		d1.setSalary(100.00);
		
		List<String> ph1 = new ArrayList<String>();
		ph1.add("110");
		ph1.add("120");
		d1.setPhones(ph1);
		
		Address a1 = new Address("Shenzhen", "China");
		Address a2 = new Address("NewYork", "USA");
		Map<String, Address> adds = new HashMap<String, Address>();
		adds.put("SZX", a1);
		adds.put("NYX", a2);
		d1.setAddresses(adds);
		
		em.persist(d1);

		em.getTransaction().commit();

		em.close();
		emf.close();
	}
}
